package com.nulldev.util.web.HttpServer3.extensions.nCaptcha.backend;

import com.nulldev.util.data.Date.Dates;
import com.nulldev.util.languages.json.uniapi.UniJsonValue;
import com.nulldev.util.web.HttpServer3.Response;
import com.nulldev.util.web.HttpServer3.pages.v3.HttpPage3;

public class CaptchaJSONPage extends HttpPage3 {

	private static final String JSON_MIME = "application/json; charset=utf-8";

	public CaptchaJSONPage() {
		super("/captcha-json", true);
		super.setCachingMethod(CachingMethod.NO_CACHE);
	}

	@SuppressWarnings("resource")
	@Override
	public Response onRequest(final Request request) {
		final UniJsonValue out = UniJsonValue.object(1);
		final UniJsonValue error = UniJsonValue.object(2);
		error.add("reason", "NCAPTCHA_SOLUTION_REQUIRED");
		error.add("time", Dates.nowISO());
		out.add("error", error);
		return new Response(200, out, out).setCustomMime(JSON_MIME);
	}

}
